//轮播图

$(document).ready(() => {

    // $('.slider-image').on("load", function() {
    //     // do stuff
    //     setSliderBg(this)

    //   }).each(function() {
    //     if(this.complete) {
    //         setSliderBg(this)
    //     }
    //   });
    $.adaptiveBackground.run({
        success: function($img, data) {
            console.log('Success!', $img, data);
        }
    });

    const items = [];
    const indicatorItem = []

    $('.slider-img').each((i, n) => {
        items.push({
            position: i,
            el: document.getElementById('carousel-item-' + (i + 1))
        })
        indicatorItem.push({
            position: i,
            el: document.getElementById('carousel-indicator-' + (i + 1))
        })
    })

    const options = {
        activeItemPosition: 1,
        interval: 3000,
        
        indicators: {
            activeClasses: 'bg-white dark:bg-gray-800',
            inactiveClasses: 'bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800',
            items: indicatorItem
        },
        
        // callback functions
        onNext: () => {
            console.log('next slider item is shown');
        },
        onPrev: ( ) => {
            console.log('previous slider item is shown');
        },
        onChange: ( ) => {
            console.log('new slider item has been shown');
        }
    };
    const carousel = new Carousel(items, options);

    const prevButton = document.getElementById('data-carousel-prev');
    const nextButton = document.getElementById('data-carousel-next');

    prevButton.addEventListener('click', () => {
        carousel.prev();
    });

    nextButton.addEventListener('click', () => {
        carousel.next();
    });

    
    carousel.cycle();
    

})